package com.guoyh.bilbase.ext

import android.app.Activity
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModelProvider
import com.guoyh.baseutils.viewModel.SupportViewModel

/**
 * @CreateDate: 7/20/21 3:29 PM
 * @Author: guoyh
 * @Description: java类作用描述
 */
fun Activity.getIntentStr(key: String, default: String = "") = run {
    val str = intent.getStringExtra(key)
    if (str.isNullOrEmpty()) {
        default
    } else {
        str
    }
}

fun Activity.getIntentBoolen(key: String, default: Boolean = false) = run {
    try {
        val bool = intent.getBooleanExtra(key, default)
        bool
    } catch (e: Exception) {
        default
    }
}

fun <T : SupportViewModel> AppCompatActivity.createViewModel(modelClass: Class<T>) =
    ViewModelProvider(this).get(modelClass)

